<?php

namespace backend\controllers;


use backend\component\BackendBaseController;
use backend\component\ResultFormat;
use backend\service\CategoryService;
use common\models\info\Category;
use common\utils\CommonUtil;

class CategoryController extends BackendBaseController
{
    public function actions()
    {
        return [
            "modify" => [
                'class' => "backend\actions\ModifyAction",
                'modelName'=> Category::className()
            ],
            "delete" =>[
                'class' => "backend\actions\DeleteAction",
                'modelName'=> Category::className(),
                'is_physics' => false
            ],
            "switch" => [
                "class" => "backend\actions\SwitchAction",
                "modelName" => Category::className(),
                "field" => "status",
            ],
        ];
    }

    /*
     * 分类列表
     */
    public function actionList() {
        $data= CategoryService::categoryList(\Yii::$app->request->post());
        return ResultFormat::success('SUCCESS',json_decode($data));
    }
    public function actionDelete(){
        $id = \Yii::$app->request->get("id",0);
        return CategoryService::deleteCategory($id);
    }

    public function actionEdit() {
        $id = \Yii::$app->request->get("id",0);
        $model = Category::modelById($id);
        return ResultFormat::success('SUCCESS',$model->attributes);
    }
}